package com.mike.ad.service.impl;

import com.mike.ad.dao.AdCreativeRepository;
import com.mike.ad.entity.AdCreative;
import com.mike.ad.service.IAdCreativeService;
import com.mike.ad.vo.AdCreativeRequest;
import com.mike.ad.vo.AdCreativeResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AdCreativeServiceImpl implements IAdCreativeService {
    private final AdCreativeRepository adCreativeRepository;

    @Autowired
    public AdCreativeServiceImpl(AdCreativeRepository adCreativeRepository) {
        this.adCreativeRepository = adCreativeRepository;
    }

    @Override
    @Transactional
    public AdCreativeResponse createCreative(AdCreativeRequest request) {
        AdCreative creative = adCreativeRepository.save(request.convertToEntity());
        return new AdCreativeResponse(creative.getId(), creative.getName());
    }
}
